<?php
/**
 * 后台首页
 * Created by PhpStorm.
 * User: zhangbing
 * Date: 2018/7/20
 * Time: 15:45
 */
namespace app\admin\controller;

class Index extends Base{
    protected function _initialize(){
        $this->needAuth = false;  // 关闭权限验证
        parent::_initialize();
    }

    /**
     * 首页
     * @return \think\response\View
     */
    public function index(){
        // 获取登录信息
        return view('index',[
            'info' => json_encode($this->info)
        ]);
    }

    /**
     * 查询菜单列表
     * @return array
     */
    public function searchMenu(){
        if (IS_AJAX && IS_POST) {
            // 超级管理员至高无上
            $where = $this->id == \Param::GROUP_ADMIN ? ['a.status'=>\Param::STATUS_ON, 'b.pid'=>0] : ['a.id'=>['in',$this->info['auth_ids']],'a.status'=>\Param::STATUS_ON, 'b.pid'=>0];
            // 获取当前用户具备的二级权限
            $auth_rules  = $this->joinMany(
                $this->auth_rule,
                [['auth_rule b', 'a.pid = b.id','left']],
                $where,
                'a.rule_name,a.auth_rule,b.pid'
            );
            $search_menu = [];
            foreach ($auth_rules as $k=>$v) {
                $search_menu[] = ['value'=>$v['rule_name'],'address'=>$v['auth_rule']];
            }
            return success($search_menu);
        }
    }
}